package com.jichangxiu.server.platform.action;

import cn.hutool.core.collection.ListUtil;
import com.jichangxiu.common.annotation.*;
import com.jichangxiu.common.entity.bo.PageData;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.server.platform.entity.dto.PlatformDictTypeQueryDto;
import com.jichangxiu.server.platform.entity.vo.PlatformDictTypeAddVo;
import com.jichangxiu.server.platform.entity.vo.PlatformDictTypeEditVo;
import com.jichangxiu.server.platform.entity.vo.PlatformDictTypeQueryVo;
import com.jichangxiu.server.platform.service.PlatformDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * PlatformDictTypeAction:
 * 平台-字典类型管理控制器
 *
 * @author Jcx
 * @create 2023-02-25 22:10
 */
@Slf4j
@Rest("/platform/dict/type")
@Tag(name = "平台-字典类型管理控制器")
public class PlatformDictTypeAction extends BaseAction {

    @Resource
    private PlatformDictTypeService platformDictTypeService;

    /**
     * 新增字典类型
     *
     * @param platformDictTypeAddVo 字典类型视图对象
     * @return 是否成功
     */
    @Post("/add")
    @Operation(summary = "平台-新增字典类型")
    @PreAuthorize("@ss.hasPermission('platform:dictType:add')")
    public String add(@RequestBody PlatformDictTypeAddVo platformDictTypeAddVo) {
        return toStr(platformDictTypeService.add(platformDictTypeAddVo));
    }

    /**
     * 多选级联删除字典类型
     *
     * @param dictIds 字典类型ID列表
     * @return 是否成功
     */
    @Delete("/del")
    @Operation(summary = "平台-多选级联删除字典类型")
    @PreAuthorize("@ss.hasPermission('platform:dictType:del')")
    public String del(@RequestBody String[] dictIds) {
        return toStr(platformDictTypeService.del(ListUtil.toList(dictIds)));
    }

    /**
     * 修改字典类型信息
     *
     * @param platformDictTypeEditVo 字典类型视图对象
     * @return 是否成功
     */
    @Put("/edit")
    @Operation(summary = "平台-修改字典类型信息")
    @PreAuthorize("@ss.hasPermission('platform:dictType:edit')")
    public String edit(@RequestBody PlatformDictTypeEditVo platformDictTypeEditVo) {
        return toStr(platformDictTypeService.edit(platformDictTypeEditVo));
    }

    /**
     * 根据ID获取字典类型详情
     *
     * @param dictId 字典类型ID
     * @return 字典类型详情
     */
    @Get("/info/{dictId}")
    @Operation(summary = "平台-根据ID获取字典类型详情")
    @PreAuthorize("@ss.hasPermission('platform:dictType:info')")
    public PlatformDictTypeQueryDto info(@PathVariable("dictId") @NotBlank(message = "字典类型ID不能为空") String dictId) {
        return platformDictTypeService.info(dictId);
    }

    /**
     * 分页查询字典类型列表
     *
     * @param platformDictTypeQueryVo 字典类型视图对象
     * @return 分页字典类型列表
     */
    @Get("/pageList")
    @Operation(summary = "平台-分页查询字典类型列表")
    @PreAuthorize("@ss.hasPermission('platform:dictType:pageList')")
    public PageData<PlatformDictTypeQueryDto> pageList(@ParameterObject PlatformDictTypeQueryVo platformDictTypeQueryVo) {
        return platformDictTypeService.pageList(platformDictTypeQueryVo);
    }

}
